package expo43server;

/*
 * 
 * THINGS THIS SERVER DOES:
 * Break the intro loop
 * Start ITopia film
 * start the game
 * start the credits
 */
import itopiamme.PhidgetHandler;
import java.net.*;
import java.io.*;

/**
 *
 * @author TommySprat
 */
public class Expo43GameStartingServer extends Thread {

    String inputLine, outputLine; //Keep or trash?
    ServerSocket serverSocket;
    Socket clientSocket;
    PrintWriter out;
    PhidgetHandler mainPhidgetHandler;

    public Expo43GameStartingServer(PhidgetHandler mainPhidgetHandler) {

        this.mainPhidgetHandler = mainPhidgetHandler;
    }

    @Override
    public void run() {

        serverSocket = null;
        try {
            serverSocket = new ServerSocket(4450);
        } catch (IOException e) {
            System.err.println("Could not listen on port: 4450.");
            System.exit(1);
        }

        clientSocket = null;
        try {
            //Waits until a client connects on serverSocket
            clientSocket = serverSocket.accept();
            System.out.println("Client connected");
        } catch (IOException e) {
            System.err.println("Accept failed.");
            System.exit(1);
        }

        try {
            out = new PrintWriter(clientSocket.getOutputStream(), true);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    clientSocket.getInputStream()));
        } catch (IOException exc) {
            System.out.println("Error in Expo43GameStartingServer with IO setup");
        }

        out.println("Welcome e43GameStartingClient");
    }

    public void startGame() {
        out.println("startgame");
    }
}
